﻿<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" 
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
				xmlns:ms="urn:schemas-microsoft-com:xslt" 
				xmlns:dsml="http://www.dsml.org/DSML" 
				xmlns:ms-dsml="http://www.microsoft.com/MMS/DSML"
				xmlns:msxml="urn:schemas-microsoft-com:xslt"
			    xmlns:mv="urn:my-scripts">
  <xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes" />
  <xsl:variable name="schemaData" select="mv:parse(//ExportObject/ResourceManagementObject[ObjectType='mv-data']/ResourceManagementAttributes/ResourceManagementAttribute[AttributeName='SyncConfig-schema']/Value)" />

	<xsl:template match="/">
 			<xsl:call-template name="MVSchema" />
	</xsl:template>
	<!--======================================================================================-->
	<!-- Template to display the Metaverse schema                                             -->
	<!--======================================================================================-->
	<xsl:template name="MVSchema">
    <table id="tdata">
      <xsl:call-template name="tablestyle" />
      <tr>
        <td colspan="5">
          <xsl:call-template name="reportheadstyle" />
          <xsl:text>FIM Metaverse Schema</xsl:text>
        </td>
			</tr>

			<xsl:for-each select="$schemaData/dsml:dsml/dsml:directory-schema/dsml:class">
				<xsl:sort select="@id"/>
				<xsl:variable name="object-type" select="@mv-object-type" />
        <xsl:call-template name="sectionbreak">
          <xsl:with-param name ="colspan" select="'6'" />
        </xsl:call-template>
				<tr>
					<td colspan="4">
            <xsl:call-template name="sectionstyle" />
            <xsl:text>Metaverse object type: </xsl:text>
						<xsl:value-of select="@id"/>
					</td>
				</tr>
				<tr>
          <th><xsl:call-template name="headstyle" />Attribute Name</th>
          <th><xsl:call-template name="headstyle" />Type</th>
          <th><xsl:call-template name="headstyle" />Multi-Valued</th>
          <th><xsl:call-template name="headstyle" />Indexable</th>
				</tr>
				<xsl:for-each select="dsml:attribute">
          <xsl:variable name="aName" select="substring(@ref,2)"></xsl:variable>
          <tr>
            <xsl:call-template name="multiline" />
            <td>
              <xsl:call-template name="centercell" />
              <xsl:value-of select="//dsml:attribute-type[@id=$aName]/dsml:name"/>
            </td>
            <td>
              <xsl:call-template name="centercell" />
              <xsl:variable name ="oid"  select="//dsml:attribute-type[@id=$aName]/dsml:syntax" />
              <xsl:choose>
                <xsl:when test="$oid='1.3.6.1.4.1.1466.115.121.1.27'" >
                  <xsl:text>Number</xsl:text>
                </xsl:when>
                <xsl:when test="$oid='1.3.6.1.4.1.1466.115.121.1.12'" >
                  <xsl:text>Reference (DN)</xsl:text>
                </xsl:when>
                <xsl:when test="$oid='1.3.6.1.4.1.1466.115.121.1.7'" >
                  <xsl:text>Boolean</xsl:text>
                </xsl:when>
                <xsl:when test="$oid='1.3.6.1.4.1.1466.115.121.1.5'" >
                  Binary
                  <xsl:call-template name="isindexable" />
                </xsl:when>
                <xsl:when test="$oid='1.3.6.1.4.1.1466.115.121.1.15'" >
                  String
                  <xsl:call-template name="isindexable" />
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="$oid" />
                </xsl:otherwise>
              </xsl:choose>
            </td>
            <td>
              <xsl:call-template name="centercell" />
              <xsl:choose>
                <xsl:when test="//dsml:attribute-type[@id=$aName]/@single-value">
                  <xsl:text>no</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:text>yes</xsl:text>
                </xsl:otherwise>
              </xsl:choose>
            </td>
            <td>
              <xsl:call-template name="centercell" />
              <xsl:choose>
                <xsl:when test="//dsml:attribute-type[@id=$aName]/@ms-dsml:indexable">
                  <xsl:text>yes</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:text>no</xsl:text>
                </xsl:otherwise>
              </xsl:choose>
            </td>
					</tr>
				</xsl:for-each>
			</xsl:for-each>
		</table>
	</xsl:template>
  <!--===================================================================================================================================-->
  <!-- Template to determine whether a value is indexable                                                                                -->
  <!--===================================================================================================================================-->
  <xsl:template name="isindexable">
    <xsl:param name="value" />
    <xsl:choose>
      <xsl:when test="//dsml:attribute-type[@id=$value]/@ms-dsml:indexable='true'" >
        <xsl:text> (indexable)</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text> (non-indexable)</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a table style                                                        -->
  <!--======================================================================================-->
  <xsl:template name="tablestyle">
    <xsl:attribute name="style">
      font-family:Tahoma;
      font-size:11px;
      border-top:1px RGB(212,208,200) solid;
      border-left:1px RGB(212,208,200) solid;
      border-right: 1px RGB(212,208,200) solid;
      border-bottom:1px RGB(212,208,200) solid;
      padding:0px;"
    </xsl:attribute>
  </xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a report head style                                                  -->
  <!--======================================================================================-->
  <xsl:template name="reportheadstyle">
    <xsl:attribute name="style">
      padding-top:10px;
      padding-bottom:10px;
      padding-left:10px;
      padding-right:10px;
      font-weight:bold;
      background:rgb(234,242,255);
      border-bottom:1px solid rgb(120,172,255)
    </xsl:attribute>
  </xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a section style                                                        -->
  <!--======================================================================================-->
  <xsl:template name="sectionstyle">
    <xsl:attribute name="style">
      text-align:left;
      border-bottom:green 1px solid;
      padding-bottom:5px;
      padding-left:10px;
      padding-right:10px;
      background:#e9ffcb;
      font-weight:bold;
      padding-top:5px
    </xsl:attribute>
  </xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a section break                                                      -->
  <!--======================================================================================-->
  <xsl:template name="sectionbreak">
    <xsl:param name="colspan" />
    <xsl:if test="position()!=1">
      <tr>
        <td style="color:#FFFFFF;background-color:#FFFFFF; border-top:1px RGB(212,208,200) solid;" >
          <xsl:attribute name="colspan">
            <xsl:value-of select="$colspan"/>
          </xsl:attribute>
          &#160;
        </td>
      </tr>
    </xsl:if>
  </xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a section break                                                      -->
  <!--======================================================================================-->
  <xsl:template name="multiline">
    <xsl:if test="(position() mod 2 = 0)">
      <xsl:attribute name="bgcolor">#F5F5DC</xsl:attribute>
    </xsl:if>
  </xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a head style                                                         -->
  <!--======================================================================================-->
  <xsl:template name="headstyle">
    <xsl:attribute name="style">
      background:#CCCCCC;
      border-right:#666666 1px solid;
      border-bottom:#666666 1px solid;
      padding-left:10px;
      padding-right:10px;
      font-weight:normal;
      white-space:nowrap;
    </xsl:attribute>
  </xsl:template>
  <!--======================================================================================-->
  <!-- Template to add a center cell                                                        -->
  <!--======================================================================================-->
  <xsl:template name="centercell">
    <xsl:attribute name="style">
      padding-left:10px;
      padding-right:10px;
      white-space:nowrap;
      text-align:center;
      font-weight:normal;"
    </xsl:attribute>
  </xsl:template>
  <!--===================================================================================================================================-->
  <!-- Script to convert XML Text into XML Node List                                                                                     -->
  <!--===================================================================================================================================-->
	<msxml:script language="CSharp" implements-prefix="mv">
		<msxml:using namespace="System.IO" />
		public XPathNodeIterator parse(string data)
		{
		String xmlString = "&lt;root&gt;" + data + "&lt;/root&gt;";
		StringReader stringReader = new StringReader(xmlString);

		XPathDocument xPathDocument = new XPathDocument(stringReader);
		XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();

		return xPathNavigator.Select("root");
		}
	</msxml:script>
</xsl:stylesheet>